package com.nameless.controller.web;

import com.nameless.entity.Car;
import com.nameless.entity.Coupon;
import com.nameless.service.CouponHistoryService;
import com.nameless.vo.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2023/03/03 14:22
 * @Description
 */
@RestController
@RequestMapping("/coupon/web/couponHistory")
@Api("优惠劵历史api信息操作接口")
public class WebCouponHistoryController {

    @Autowired
    private CouponHistoryService couponHistoryService;

    /**
     * 后台为用户送优惠券
     *
     * @param couponId 优惠券id
     * @return {@link Result}<{@link String}>
     */
    @GetMapping("toReceiveCoupon/{couponId}")
    public Result<String> toReceiveCoupon(@PathVariable Long couponId) {
        return couponHistoryService.toReceiveCoupon(couponId);
    }

    /**
     * 用户使用优惠券
     *
     * @param couponId 优惠券id
     * @param orderNo 订单sn
     * @return {@link Result}<{@link String}>
     */
    @GetMapping("/useCoupon/{couponId}/{orderNo}")
    public Result<String> useCoupon(@PathVariable Long couponId ,@PathVariable String orderNo){
        return couponHistoryService.useCoupon(couponId,orderNo);
    }

    /**
     * 根据用户查询优惠劵
     *
     * @param car 车
     * @return {@link Result}<{@link Map}<{@link String}, {@link Coupon}>>
     */
    @PostMapping("getCouponByClientId")
    public Result<Map<String, List<Coupon>>> getCouponByClientId(@RequestBody Car car){
        Map<String, List<Coupon>> couponMap = couponHistoryService.getCouponByClientId(car);
        return Result.success(couponMap);
    }
}
